package com.cn.jinl.controller;

import com.cn.jinl.api.IProcureStorageService;
import com.cn.jinl.domain.ProcureStorage;
import com.cn.jinl.domain.ProcureStorageHis;
import com.cn.jinl.domain.ProcureVo;
import com.cn.jinl.utils.CommonUtil;
import com.cn.jinl.utils.JsonResponse;
import com.cn.jinl.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/procureStorage")
public class ProcureStorageController {

    @Autowired
    private IProcureStorageService procureStorageService;

    @RequestMapping("/getProcureStorageList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<ProcureStorage>> getProcureStorageList(@PathVariable(value = "frontToken",required = true) String frontToken, @RequestBody QueryForm queryForm) throws Exception{
        JsonResponse<List<ProcureStorage>> response = new JsonResponse<>();
        List<ProcureStorage> procureStorages = procureStorageService.getProcureStorageList(queryForm);
        response.setResult(procureStorages);
        response.setSuccess(true);
        return response;
    }

    @RequestMapping("/getProcureStorageDetailList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<ProcureStorage>> getProcureStorageDetailList(@PathVariable(value = "frontToken",required = true) String frontToken, QueryForm queryForm) throws Exception{
        JsonResponse<List<ProcureStorage>> response = new JsonResponse<>();
        List<ProcureStorage> procureStorages = procureStorageService.getProcureStorageDetailList(queryForm);
        response.setResult(procureStorages);
        response.setSuccess(true);
        return response;
    }

    @RequestMapping("/getProcureStorageHistoryList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<ProcureStorageHis>> getProcureStorageHistoryList(@PathVariable(value = "frontToken",required = true) String frontToken, String id) throws Exception{
        JsonResponse<List<ProcureStorageHis>> response = new JsonResponse<>();
        List<ProcureStorageHis> procureStorages = procureStorageService.getProcureStorageHistoryList(id);
        response.setResult(procureStorages);
        response.setSuccess(true);
        return response;
    }

    @RequestMapping("/getProcureStorageHistoryListByPid/{frontToken}")
    @ResponseBody
    public JsonResponse<List<ProcureStorageHis>> getProcureStorageHistoryListByPid(@PathVariable(value = "frontToken",required = true) String frontToken, String id) throws Exception{
        JsonResponse<List<ProcureStorageHis>> response = new JsonResponse<>();
        List<ProcureStorageHis> procureStorages = procureStorageService.getProcureStorageHistoryListByPid(id);
        response.setResult(procureStorages);
        response.setSuccess(true);
        return response;
    }

    @RequestMapping("/batchInsertProcureStorageHis/{frontToken}")
    @ResponseBody
    public JsonResponse<String> batchInsertProcureStorageHis(@RequestBody List<ProcureStorageHis> procureStorageHis, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = procureStorageService.batchInsertProcureStorageHis(procureStorageHis);
        return CommonUtil.getResponseData(response,result);
    }


    @RequestMapping("/getProcureStorageListByMaterialCode/{frontToken}")
    @ResponseBody
    public JsonResponse<List<ProcureVo>> getProcureStorageListByMaterialCode(QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<List<ProcureVo>> response = new JsonResponse<>();
        List<ProcureVo> procureStorages = procureStorageService.getProcureStorageListByMaterialCode(queryForm);
        response.setResult(procureStorages);
        response.setSuccess(true);
        return response;
    }

    //获取入库信息
    @RequestMapping("/api/getAPIProcureStorageListById")
    @ResponseBody
    public JsonResponse<List<ProcureStorage>> getAPIProcureStorageListById(String id) throws Exception{
        JsonResponse<List<ProcureStorage>> response = new JsonResponse<>();
        List<ProcureStorage> procureStorages = procureStorageService.getAPIProcureStorageListById(id);
        response.setResult(procureStorages);
        response.setSuccess(true);
        return response;
    }


}
